package com.yanqu.road.server.cross3server.cmd.server;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross3.server.CrossChannelRouteProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.protocol.Cross3Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Cross3Protocol.C3_ROUTE_GAME_MSG, desc = "转发到游戏服")
public class RouteGameMsgCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossChannelRouteProto.RouteGameMsg reqMsg = CrossChannelRouteProto.RouteGameMsg.parseFrom(packet.getBytes());

        // 拿一下真实的协议号
        int gameCode = reqMsg.getGameCode();
        long gameServerId = reqMsg.getGameServerId();
        long userId = reqMsg.getUserId();
        byte[] msg = reqMsg.getMsg().toByteArray();

        // 用真实的协议号转发到游戏服
        YanQuMessage message = YanQuMessageUtils.buildMessageByte(gameCode, msg);
        if (gameServerId == -1) {
            MessageHelper.sendAllServer(message); // 全部游戏服
        } else {
            MessageHelper.sendPacket(gameServerId, userId, message); // 单个游戏服
        }

        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

    }

    @Override
    public void sendData() {

    }
}
